package net.fpeg.msa.phonelite.controller

import net.fpeg.msa.phonelite.dto.PhoneDto
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import java.util.*

@RestController
class PhoneController {

    private var phoneList: LinkedList<PhoneDto> = LinkedList<PhoneDto>()

    @GetMapping
    fun find(
            @RequestHeader("token") token: String?
    ): LinkedList<PhoneDto>? {
        if (token=="{A7BCA828-1147-4A3B-828A-289A1B6AF239}")
            return phoneList
        return null
    }

    @PostMapping("/{region}/{number}")
    fun add(
            @PathVariable("region") region: String,
            @PathVariable("number") number: String,
    ) {
        phoneList.add(PhoneDto(region, number))
    }
}